package com.rentcars.controller;

import com.rentcars.entity.Resource;
import com.rentcars.service.RoleResourceService;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 类描述：
 *
 * @author 张吉哲
 * @date 2021/3/1 10:41
 */
@Controller
public class WelcomeController {

  private final RoleResourceService roleResourceService;

  public WelcomeController(
      RoleResourceService roleResourceService) {
    this.roleResourceService = roleResourceService;
  }

  @RequestMapping(value = "/")
  public String login() {
    return "login.html";
  }

  @RequestMapping(value = "/home")
  public String home(HttpSession session) {
    String username = (String) session.getAttribute("username");
    List<Resource> resources = roleResourceService.selectResourcesByUsername(username);
    session.setAttribute("resources", resources);
    return "home";
  }

  @RequestMapping(value = "/welcome")
  public String welcome() {
    return "welcome";
  }
}
